import logging

# 1.显示创建
logging.basicConfig(filename='logger.log', format='%(asctime)s - %(levelname)s - %(threadName)s - %(filename)s [Ln:%(lineno)d] - %(message)s',level=logging.INFO)

# 2.定义logger,设定setLevel，FileHandler，setFormatter
logger = logging.getLogger(__name__)   	#定义一次就可以，其他地方需要调用logger,只需要直接使用logger就行了
logger.setLevel(level=logging.INFO)  	#定义过滤级别

formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(threadName)s - %(filename)s [Ln:%(lineno)d] - %(message)s')

console = logging.StreamHandler()  		#日志信息显示在终端terminal
console.setLevel(logging.INFO)
console.setFormatter(formatter)

logger.addHandler(console)